/*
 * Find two elements in a array, their sum is x.
 */
import java.util.Arrays;
class FindPairedSum{
	public static void findSum(int[] array, int target){
		Arrays.sort(array); // sort Array
		int i=0;
		int j=array.length-1;
		int sum=0;
		while(i<j){
			sum = array[i]+array[j];
			if(sum == target){
				System.out.println(array[i]+" "+array[j]);
				++i;
				--j;
				//break;
			} else if (sum > target){
				j--;
			}else{
				i++;
			}
			
		}
	}
	
	public static void main(String[] args){
		int[] a = {4,2,5,6,1,3,9};
		findSum(a,10);
	}
}